package jhh.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jhh.service.Ant_JmeterImp;
import jhh.service.Delete;
import jhh.service.iface.Jmeter;






/**
 * Servlet implementation class Ant
 */
@WebServlet("/Ant")
public class Ant extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Ant() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("text/html;charset=utf-8");
		String path=this.getServletContext().getRealPath("WEB-INF/build.xml");
		String JmxPath=this.getServletContext().getRealPath("result");
		Delete del=new Delete();
		del.deleteAll(JmxPath);
		PrintWriter pw=response.getWriter();
		pw.write("测试执行中 请稍候");
		pw.flush();
		Jmeter a=new Ant_JmeterImp();
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
		Date date1=null;
		Date date2=null;
		try {
			date1=df.parse(df.format(new Date()));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		a.DoJmx(path);
		try {
			date2=df.parse(df.format(new Date()));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
/*		long l = date1.getTime() - date2.getTime();

		long day=l/(24*60*60*1000);
	    long hour=(l/(60*60*1000)-day*24);
        long min=((l/(60*1000))-day*24*60-hour*60);
        long s=(l/1000-day*24*60*60-hour*60*60-min*60);
        
        pw.write("执行时间为："+day+"天"+hour+"小时"+min+"分钟"+s+"秒");
        pw.write("<a href='AnalysisJtl'>分析测试结果</a>");*/
		
		pw.close();
	}
	
	}





